package ua.kharkov.knure.pereverziev.diploma.web.command;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

public class ReturnFlightChoiceCommand implements Command {
	private static final Logger log = Logger
			.getLogger(CreateTicketCommand.class);

	@Override
	public String execute(final HttpServletRequest request,
			final HttpServletResponse response) throws IOException,
			ServletException {
		log.info("Executing ReturnFlightCommand.execute ");

		final HttpSession session = request.getSession();

		final String returnFlightNumber = request.getParameter("choice");
		log.trace("Request parameter: choice --> " + returnFlightNumber);

		log.trace("Request parameter: returnFlightNumber --> "
				+ returnFlightNumber);

		String forward = "/WEB-INF/jsp/error_page.jsp";

		// ============================================================
		// ============= Saving parameter into a ticket Bean ==========

		if (returnFlightNumber != null) {

			forward = "/WEB-INF/jsp/placeSelection.jsp";
		}

		session.setAttribute("lastPage", forward);
		return forward;
	}

}
